import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const routes = [
  {
    path: '/test',
    name: 'test',
    component: () => import('../views/test.vue'),
  },
  // 豆,首页,预约试驾
  {
    path: '/',
    name: 'BydIndex',
    component: () => import('../views/BydIndex.vue'),
    redirect: '/indexmain',
    children: [
      {
        path: 'indexmain',
        name: 'indexmain',
        component: () => import('../views/IndexMain.vue'),
      },
      {
        path: 'bydlocation',
        name: 'bydlocation',
        component: () => import('../views/BydLocation.vue'),
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue'),
  },
  // 详情
  {
    path: '/details',
    name: 'details',
    component: () => import('../views/details.vue'),
    redirect: '/details/cardetails',
    children: [
      {
        path: 'cardetails',
        name: 'cardetails',
        component: () => import('../views/cardetails.vue'),
      },
      {
        path: 'bystages',
        name: 'bystages',
        component: () => import('../views/bystages.vue'),
      },
    ],
  },
  // 汪 参数,比较,404,列表

  {
    path: '/param',
    name: 'param',
    component: () => import('../views/Param.vue'),
  },
  {
    path: '*',
    name: 'notfound',
    component: () => import('../views/NotFound.vue'),
  },
  {
    path: '/carlist',
    name: 'carlist',
    component: () => import('../views/CarList.vue'),
  },
  {
    path: '/compare',
    name: 'compare',
    component: () => import('../views/Compare.vue'),
  },

  // 朱 后台
  {
    //管理员登录
    path: '/admin',
    name: 'routeName',
    component: () => import('../views/Admin.vue'),
  },
  {
    //后台
    path: '/backstage',
    name: 'backstage',
    component: () => import('../views/Backstage.vue'),
    redirect: '/backstage/sales',
    children: [
      {
        //销量
        path: 'sales',
        name: 'sales',
        component: () => import('../views/Sales.vue'),
        meta: {
          requireAuth: true,
        },
      },
      {
        //用户
        path: 'users',
        name: 'routeName',
        component: () => import('../views/Users.vue'),
      },
      {
        //商品
        path: 'commodity',
        name: 'routeName',
        component: () => import('../views/Commodity.vue'),
      },
      {
        //订单
        path: 'indent',
        name: 'routeName',
        component: () => import('../views/Indent.vue'),
      },
      {
        //管理员
        path: 'conservator',
        name: 'routeName',
        component: () => import('../views/Conservator.vue'),
      },
    ],
  },
  //浪
  {
    path: '/rider',
    name: 'Rider',
    component: () => import('../views/MyRing.vue'),
    redirect: '/rider/bydring',
    children: [
      {
        path: 'bydring',
        name: 'bydring',
        component: () => import('../views/BydRing.vue'),
      },
    ],
  },
  {
    path: '/centre',
    name: 'PersonalCenter',
    component: () => import('../views/PersonalCenter.vue'),
    redirect: '/centre/collet',
    children: [
      {
        path: 'collet',
        name: 'collet',
        component: () => import('../views/Collet.vue'),
      },
      {
        path: 'order',
        name: 'Order',
        component: () => import('../views/Order.vue'),
      },
      {
        path: 'announce',
        name: 'Announce',
        component: () => import('../views/Announce.vue'),
      },
      {
        path: 'reply',
        name: 'Reply',
        component: () => import('../views/Reply.vue'),
      },
    ],
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
})

// 路由守卫
// router.beforeEach((to, from, next) => {
//   let admin = sessionStorage.getItem('admin')

//   if (to.meta.requireAuth == true) {
//     // 需要登录权限进入的路由
//     if (!admin) {
//       // 获取不到登录信息
//       next({
//         path: '/admin',
//       })
//     } else {
//       // 获取到登录信息，进行下一步
//       return next()
//     }
//   } else {
//     // 不需要登录权限的路由直接进行下一步
//     return next()
//   }
// })

export default router
